import {
  Body,
  Controller,
  Delete,
  Get,
  HttpStatus,
  Param,
  Post,
  Query,
} from '@nestjs/common';
import { ExamService } from './exam.service';
import {
  ApiBody,
  ApiHeader,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { ExamEntity } from './exam.entity';

@ApiTags('考试模块')
@Controller('exam')
export class ExamController {
  constructor(private readonly examService: ExamService) {}

  // 针对get请求
  @ApiQuery({
    name: 'exam_name',
    required: true,
    description: '考试名称',
  })
  @ApiQuery({
    name: 'exam_type_id',
    required: true,
    description: '考试的类型',
  })
  //post
  @ApiBody({
    description: '请求体',
    type: ExamEntity,
  })
  @ApiHeader({
    name: 'token',
    required: true,
    description: '请求的时候 携带token',
  })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  @Post()
  create(@Body() examBody) {
    return this.examService.create(examBody);
  }

  @ApiQuery({
    name: 'count',
    required: false,
    description: '返回的条数',
  })
  @ApiResponse({ status: HttpStatus.OK, description: '请求成功' })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  @Get()
  getAll() {
    return this.examService.getAll();
  }

  // swagger
  @ApiQuery({
    name: 'id',
    required: true,
    description: '考试id',
  })
  @ApiResponse({ status: HttpStatus.OK, description: '请求成功' })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  // 请求处理
  @Get(':id')
  // @Query('id') :?id=123
  // @Param 地址 /exam/123
  getOne(@Param('id') id) {
    return this.examService.getOne(id);
  }

  // swagger
  @ApiQuery({
    name: 'id',
    required: true,
    description: '考试id',
  })
  @ApiResponse({ status: HttpStatus.OK, description: '请求成功' })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  @Delete(':id')
  deleteById(@Param('id') id: string) {
    return this.examService.deleteById(id);
  }
}
